<?php
	/**
 	 * Application configuration controller class
 	 */
	class LanguagesController extends Controller
	{
		/**
	 	 * page title
	 	 */
		public $page_title = LANG_LANGUAGES;
		
		/**
	 	 * page layout
	 	 */
		public $layout = 'main';
		
		/**
	 	 * necessary helpers
	 	 */
		public $helpers = array ("html", "htmlx", "toolbars");
		
		/**
	 	 * necessary javascript files
	 	 */
		public $javascript = array("TreeMenu");
		
		/**
	 	 * necessary components
	 	 */
		public $components = array ("TreeMenu");
		
		
		function edit($lang)
		{
			$this->data[lang] = $lang;
	
			if ($_POST['submitTrans'] == 'submit')
			{
				//make copy and rewrite the file
				//copy(LANGUAGES.SEPARATOR.$this->data[lang].SEPARATOR.'text.php',LANGUAGES.SEPARATOR.$this->data[lang].SEPARATOR.'text_backup.php');
				$fp = fopen('././app/includes/languages/'.$this->data[lang].SEPARATOR.'text.php', 'w+');
				fwrite($fp, "<?php \n");
				while ($elem = each($_POST))
				{
					$output = "define('".$elem["key"]."','".$elem["value"]."');\n";
					fwrite($fp, $output);
				}
				fwrite($fp, "?>");
				fclose($fp);
				$out.='<br/>'.LANG_TRANSLATION_UPDATED.'<br />';		
			}		
			
			//reads the file
			$trans_line = file('././app/includes/languages/'.$this->data[lang].SEPARATOR.'text.php');
			$trans_num = count($trans_line);
			for ($i=1; $i<$trans_num; $i++)
			{
				$trans = explode("','", $trans_line[$i]);
				$trans = str_replace("define('", "", $trans);
				$trans = str_replace("');", "", $trans);
				if (!ereg("^[A-Z]" ,$trans[0])) {continue;}
				$tr[$i][0]=$trans[0];
				$tr[$i][1]=$trans[1];
			}
			$this->data[trans_num] = $trans_num;
			$this->data[tr] = $tr;			
			$this->data[out] = $out;			
			
		}
	}
?>